package com.fr.report.web.ui;

import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.util.Utils;
import com.fr.web.Repository;

public class Button extends Widget
{
  public static final String EVENT_AFTERINIT = "afterinit";
  public static final String EVENT_CLICK = "click";
  protected String text;
  protected String iconName;
  protected boolean showIcon = true;
  protected boolean showText = true;
  protected String hotkeys;

  public Button()
  {
  }

  public Button(String paramString)
  {
    this.text = paramString;
  }

  public Button(String paramString1, String paramString2)
  {
    this.text = paramString1;
    this.iconName = paramString2;
  }

  public boolean getShowIcon()
  {
    return this.showIcon;
  }

  public void setShowIcon(boolean paramBoolean)
  {
    this.showIcon = paramBoolean;
  }

  public boolean getShowText()
  {
    return this.showText;
  }

  public void setShowText(boolean paramBoolean)
  {
    this.showText = paramBoolean;
  }

  public String getHotkeys()
  {
    return this.hotkeys;
  }

  public void setHotkeys(String paramString)
  {
    this.hotkeys = paramString;
  }

  public String getXType()
  {
    return "button";
  }

  public boolean isEditor()
  {
    return false;
  }

  public String[] supportedEvents()
  {
    return new String[] { "afterinit", "click" };
  }

  public String getText()
  {
    return this.text;
  }

  public String getIconName()
  {
    return this.iconName;
  }

  public void setText(String paramString)
  {
    this.text = paramString;
  }

  public void setIconName(String paramString)
  {
    this.iconName = paramString;
  }

  protected JSONObject createChildConfig(Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("src", getText());
    localJSONObject.put("iconSrc", FRContext.getWidgetManager().getIconManager().getCssInfo(getIconName(), paramRepository.getServletURL()));
    localJSONObject.put("showIconSrc", getShowIcon());
    localJSONObject.put("showTextSrc", getShowText());
    return localJSONObject;
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    localJSONObject.put("render", true);
    if ((this.text != null) && (getShowText()))
      localJSONObject.put("text", getText());
    else if ((paramObject != null) && (getShowText()))
      localJSONObject.put("text", Utils.objectToString(paramObject));
    if (StringUtils.isNotEmpty(this.hotkeys))
      localJSONObject.put("hotkeys", this.hotkeys);
    if ((this.iconName != null) && (getShowIcon()))
      localJSONObject.put("icon", FRContext.getWidgetManager().getIconManager().getCssInfo(this.iconName, paramRepository.getServletURL()));
    return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Text"))
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setText(str2);
      else if (str1.equals("Hotkeys"))
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setHotkeys(str2);
      else if (str1.equals("ShowIcon"))
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setShowIcon(new Boolean(str2).booleanValue());
      else if (str1.equals("ShowText"))
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setShowText(new Boolean(str2).booleanValue());
      else if (str1.equals("IconName"))
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setIconName(str2);
      else if (Icon.XML_TAG.equals(str1))
        if ((str2 = paramXMLableReader.getAttr("name")) != null)
          setIconName(str2);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (StringUtils.isNotBlank(this.text))
      paramXMLPrintWriter.startTAG("Text").textNode(this.text).end();
    if (StringUtils.isNotBlank(this.hotkeys))
      paramXMLPrintWriter.startTAG("Hotkeys").textNode(this.hotkeys).end();
    if (!(this.showIcon))
      paramXMLPrintWriter.startTAG("ShowIcon").textNode(String.valueOf(this.showIcon)).end();
    if (!(this.showText))
      paramXMLPrintWriter.startTAG("ShowText").textNode(String.valueOf(this.showText)).end();
    if (this.iconName != null)
      paramXMLPrintWriter.startTAG("IconName").textNode(String.valueOf(this.iconName)).end();
  }

  public boolean equals(Object paramObject)
  {
    if ((paramObject == null) || (!(paramObject instanceof Button)))
      return false;
    Button localButton = (Button)paramObject;
    return ((super.equals(paramObject)) && (ComparatorUtils.equals(getText(), localButton.getText())) && (ComparatorUtils.equals(getIconName(), localButton.getIconName())) && (getShowIcon() == localButton.getShowIcon()) && (getShowText() == localButton.getShowText()) && (ComparatorUtils.equals(this.hotkeys, localButton.getHotkeys())));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Button localButton = (Button)super.clone();
    return localButton;
  }
}